package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.flight.domain.vo.RevisecabinpriceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightRevisecabinprice;
import com.ktgj.flight.service.IFlightRevisecabinpriceService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票产品直降产品政策Controller
 * 
 * @author ruoyi
 * @date 2022-01-21
 */
@RestController
@RequestMapping("/flightRevisecabinprice")
public class FlightRevisecabinpriceController extends BaseController
{
    @Autowired
    private IFlightRevisecabinpriceService flightRevisecabinpriceService;

    /**
     * 查询机票产品直降产品政策列表
     */
    @PreAuthorize(hasPermi = "flight:revisecabinprice:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightRevisecabinprice flightRevisecabinprice)
    {
        startPage();
        List<FlightRevisecabinprice> list = flightRevisecabinpriceService.selectFlightRevisecabinpriceList(flightRevisecabinprice);
        return getDataTable(list);
    }

    /**
     * 导出机票产品直降产品政策列表
     */
    @PreAuthorize(hasPermi = "flight:revisecabinprice:export")
    @Log(title = "机票产品直降产品政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightRevisecabinprice flightRevisecabinprice) throws IOException
    {
        List<FlightRevisecabinprice> list = flightRevisecabinpriceService.selectFlightRevisecabinpriceList(flightRevisecabinprice);
        ExcelUtil<FlightRevisecabinprice> util = new ExcelUtil<FlightRevisecabinprice>(FlightRevisecabinprice.class);
        util.exportExcel(response, list, "机票产品直降产品政策数据");
    }

    /**
     * 获取机票产品直降产品政策详细信息
     */
//    @PreAuthorize(hasPermi = "flight:revisecabinprice:query")
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody Map<String, Object> map) {
        Long reviseid = Long.valueOf(map.get("id").toString());
        FlightRevisecabinprice flightRevisecabinprice = flightRevisecabinpriceService.selectFlightRevisecabinpriceById(reviseid);
        return AjaxResult.success(flightRevisecabinprice);
    }

    /**
     * 新增机票产品直降产品政策
     */
//    @PreAuthorize(hasPermi = "flight:revisecabinprice:add")
//    @Log(title = "机票产品直降产品政策", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(HttpServletRequest request, @RequestBody FlightRevisecabinprice flightRevisecabinprice) {
        int i;
        try {
            i = flightRevisecabinpriceService.insertRevisecabinprice(request, flightRevisecabinprice);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (i > 0){
            return AjaxResult.success("添加成功");
        }
        else {
            return AjaxResult.error("添加失败");
        }
    }

    /**
     * 修改机票产品直降产品政策
     */
//    @PreAuthorize(hasPermi = "flight:revisecabinprice:edit")
//    @Log(title = "机票产品直降产品政策", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody FlightRevisecabinprice flightRevisecabinprice) {
        int i = flightRevisecabinpriceService.updateFlightRevisecabinprice(flightRevisecabinprice);
        if (i > 0){
            return AjaxResult.success("修改成功");
        }
        else {
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除机票产品直降产品政策
     */
    @PreAuthorize(hasPermi = "flight:revisecabinprice:remove")
    @Log(title = "机票产品直降产品政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviseids}")
    public AjaxResult remove(@PathVariable Long[] reviseids)
    {
        return toAjax(flightRevisecabinpriceService.deleteFlightRevisecabinpriceByIds(reviseids));
    }

    /**
     * 删除机票产品直降产品政策
     */
    @PostMapping("/delRemove")
    public AjaxResult delRemove(@RequestBody Map<String, Object> map) {
        Long reviseid = Long.valueOf(map.get("id").toString());
        int i = flightRevisecabinpriceService.deleteFlightRevisecabinpriceById(reviseid);
        if (i > 0){
            return AjaxResult.success("删除成功");
        }
        else {
            return AjaxResult.error("删除失败");
        }
    }

    /**
     * 直降产品列表
     * */
    @PostMapping("/selectFlightRevisecabinpriceList")
    public TableDataInfo selectFlightRevisecabinpriceList(@RequestBody RevisecabinpriceVo revisecabinpriceVo) {
        startPage();
        List<FlightRevisecabinprice> flightRevisecabinprices = flightRevisecabinpriceService.selectFlightRevisecabinpriceList(revisecabinpriceVo);
        return getDataTable(flightRevisecabinprices);
    }
}
